package com.qiulingcloud.sys.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qiulingcloud.commonsserver.entity.SysUser;
import com.qiulingcloud.commonsserver.entity.vo.PageReqVO;
import com.qiulingcloud.commonsserver.entity.vo.PageVO;
import com.qiulingcloud.commonsserver.utils.PageUtil;
import com.qiulingcloud.sys.mapper.SysUserMapper;
import com.qiulingcloud.sys.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhangqiang
 * @since 2020-04-27
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {

    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public PageVO<SysUser> pageInfo(PageReqVO vo) {
        QueryWrapper<SysUser> wrapper = PageUtil.parseWhereSql(vo.getConditionJson(), vo.isAsc(), vo.getOrderFields());
        Page<SysUser> page = new Page<>(vo.getPageNum(), vo.getPageSize());
        IPage<SysUser> sysUserIPage = sysUserMapper.selectPage(page, wrapper);
        List<SysUser> userList = sysUserIPage.getRecords();
        userList.forEach(user -> {
            //TODO 这里需要添加部门名称
        });
        sysUserIPage.setRecords(userList);
        return PageUtil.getPageVO(sysUserIPage);
    }

    @Override
    public SysUser getUserByUserId(String userId) {
        return sysUserMapper.selectById(userId);
    }
}
